﻿@{
    ViewBag.Title = "登录界面";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登入 - 国家集采管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/lib/pear/css/pear.css" />
    <link rel="stylesheet" href="/lib/admin/css/other/login.css" />
    <link rel="stylesheet" href="/lib/admin/css/variables.css" />
    <script>if (window.self != window.top) { top.location.reload(); }</script>
    <script type="text/javascript" src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="~/Scripts/base64.js"></script>
    <style type="text/css">
       .login1{
           width:120px;
           height:80px;
        }
    </style>
</head>
<body>
    <div class="login-page" style="background-image: url(/lib/admin/images/background.svg)">
        <div class="layui-row">
            <div class="layui-col-sm6 login-bg layui-hide-xs">
                <img class="login-bg-img" src="/lib/admin/images/banner.png" alt="" />
            </div>
            <div class="layui-col-sm6 layui-col-xs12 login-form">
                <div class="layui-form">
                    <div class="form-center">
                        <div class="form-center-box">
                            <div class="top-log-title">
                                @*<img class="login1" src="~/lib/admin/images/logo1.png" alt="" />*@
                                <span> 国家集采管理系统</span>
                            </div>
                            <div style="margin-top: 30px;">
                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-username"></i>
                                        </div>
                                        <input lay-verify="required" placeholder="账户" autocomplete="off" name="username"
                                               class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-password"></i>
                                        </div>
                                        <input type="password" name="password" value=""
                                               lay-verify="required|confirmPassword" placeholder="密码" autocomplete="off" class="layui-input" lay-affix="eye">
                                    </div>
                                </div>
                                <div class="tab-log-verification">
                                    <div class="verification-text">
                                        <div class="layui-input-wrap">
                                            <div class="layui-input-prefix">
                                                <i class="layui-icon layui-icon-auz"></i>
                                            </div>
                                            <input lay-verify="required" value="" placeholder="验证码" name="vercode" id="vercode" autocomplete="off" class="layui-input">
                                            <canvas id="canvas" width="100" height="43"></canvas>
                                        </div>
                                    </div>
                                </div>
                                <div class="login-btn">
                                    <button lay-submit lay-filter="login" accesskey="13" class="layui-btn login">登 录</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="/layuiadmin/layui/layui.js"></script>

    <script>
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['form','index'], function () {
            var form = layui.form;
            var admin = layui.admin;
            var show_num = [];
            draw(show_num);

            $("#canvas").on('click', function () {
                draw(show_num);
            })
            // 登 录 提 交
            form.on('submit(login)', function (data) {
                var val = data.field.vercode.toLowerCase();
                var num = show_num.join("");
                if (val == '') {
                    layer.alert('请输入验证码！');
                    return false;
                }
                if (val != num) {
                    layer.alert('验证码错误！请重新输入！');
                    $("#vercode").val('');
                    draw(show_num);
                    return false;
                }
                data.field.username = BASE64.encode(data.field.username);
                data.field.password = BASE64.encode(data.field.password);
                //请求登入接口
                admin.req({
                    url: '/Home/aLogin' //实际使用请改成服务端真实接口
                    , data: data.field
                    , done: function (res) {
                        //登入成功的提示与跳转
                        layer.msg('登入成功', {
                            offset: '50px'
                            , icon: 1
                            , time: 800
                        }, function () {
                            location.href = '/Home/Index'; //后台主页
                        });
                    }
                });
                /// 验证

                /// 登录

                /// 动画
                //button.load({
                //    elem: '.login',
                //    time: 1500,
                //    done: function () {
                //        popup.success("登录成功", function () {
                //            location.href = "./index.html"
                //        });
                //    }
                //})

                return false;
            });
        })

        //验证码
        function draw(show_num) {
            var canvas_width = $('#canvas').width();
            var canvas_height = $('#canvas').height();
            var canvas = document.getElementById("canvas");//获取到canvas的对象，演员
            var context = canvas.getContext("2d");//获取到canvas画图的环境，演员表演的舞台
            canvas.width = canvas_width;
            canvas.height = canvas_height;
            var sCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0";
            var aCode = sCode.split(",");
            var aLength = aCode.length;//获取到数组的长度

            for (var i = 0; i <= 3; i++) {
                var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
                var deg = Math.random() * 30 * Math.PI / 180;//产生0~30之间的随机弧度
                var txt = aCode[j];//得到随机的一个内容
                show_num[i] = txt.toLowerCase();
                var x = 10 + i * 20;//文字在canvas上的x坐标
                var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
                context.font = "bold 23px 微软雅黑";

                context.translate(x, y);
                context.rotate(deg);

                context.fillStyle = randomColor();
                context.fillText(txt, 0, 0);

                context.rotate(-deg);
                context.translate(-x, -y);
            }
            for (var i = 0; i <= 5; i++) { //验证码上显示线条
                context.strokeStyle = randomColor();
                context.beginPath();
                context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
                context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);
                context.stroke();
            }
            for (var i = 0; i <= 30; i++) { //验证码上显示小点
                context.strokeStyle = randomColor();
                context.beginPath();
                var x = Math.random() * canvas_width;
                var y = Math.random() * canvas_height;
                context.moveTo(x, y);
                context.lineTo(x + 1, y + 1);
                context.stroke();
            }
        }

        function randomColor() {//得到随机的颜色值
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            return "rgb(" + r + "," + g + "," + b + ")";
        }
    </script>
</body>
</html>